$.ready(function () {
    $("#plan_date").datepicker({ dateFormat: "yy-mm-dd" });
    // 手机号码验证
    jQuery.validator.addMethod("isMobile", function(value, element) {
        var length = value.length;
        var mobile =  /^1(3|5|8|4)\d{9}$/;
        return this.optional(element) || (length == 11 && mobile.test(value));
    }, "请正确填写您的手机号码");
    jQuery.validator.addMethod("isIdCardNo", function(value, element) {
        var idcard_l = document.getElementById("identity").checked;
        var passport = document.getElementById("passport").checked;
        $("#lab_exist_id").remove();
        if(idcard_l){
            var result = checkIDCard(value);
            if(result){
                var type = $("#identity").val();
                var number = value;
                jQuery.ajax({
                    async:true,
                    url:url_identity,
                    data:{'card_type':type,'id_card':number},
                    type:'post',
                    success:function (data) {
                        var data = eval('(' + data + ')');
                        if(data.errcode){//存在员工档案
                            $("#lab_exist_id").remove();
                            var obj = $("input[name='identity_code']");
                            var html = '<label id="lab_exist_id" style="font-size: 12px;display: inline;color: red;"><a target="_blank" style="padding-left: 20px" href="'+data.data+'">查看</a></label>';
                            $(html).insertAfter(obj);
                            return;
                        }
                        $("#lab_exist_id").remove();

                        return;

                    }
                });
            }


            return this.optional(element) || result;
        }
        if(passport){
            //alert("paass");
            var result = true;
            //            var Expression=/(P\d{7})|(G\d{8})/;
            //            var objExp=new RegExp(Expression);
            //            if(objExp.test(value)==true){
            //                result = true;
            //            }else{
            //                result = false;
            //            }
            return this.optional(element) || result;
        }

    }, "请正确输入您的身份证号码");

    $('#form').validate({

        rules: {
            plan_date: {
                required:true
            },
            other_reason:{
                required:true,
                rangelength:[1,90]
            }








        },
        messages:{
            other_reason:{
                required:"请输入离职原因",
                rangelength:"输入90个以内的字符"
            },
            plan_date:{
                required:"请选择您的预计离职时间"
            }


        },
        errorPlacement:function (error, element) {

            // element.style.textAlign="left";
            element.parent().append(error);

        }

    });
    $.validator.setDefaults({
        submitHandler: function(form) {
            form.submit();
        }
    });
}());
